﻿// This software is the confidential and proprietary information of NetBay.
// Such confidential information should not be disclosed.
// NetBay copyright(c) 2011

using System.ComponentModel;
using System.Windows.Input;
using GalaSoft.MvvmLight.Command;
using Rio.Framework.Localisation;

namespace Rio.Framework.Pages.ChildWindows
{
    public partial class CommentChildWindow : INotifyPropertyChanged
    {
        #region Events

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region Fields

        private string _comment;
        private bool _isReadOnly;

        #endregion

        #region Properties

        public bool MustBeOpen { get; set; }

        public string Comment
        {
            get { return _comment; }
            set
            {
                _comment = value;
                OnPropertyChanged("Comment");
            }
        }

        public bool IsReadOnly
        {
            get { return _isReadOnly; }
            set
            {
                _isReadOnly = value;
                OnPropertyChanged("IsReadOnly");
            }
        }

        public RelayCommand<bool> CloseCommand { get; set; }

        #endregion

        #region Constructors

        /// <summary>
        ///   Initializes a new instance of the <see cref = "CommentChildWindow" /> class.
        /// </summary>
        public CommentChildWindow()
        {
            InitializeComponent();

            KeyUp += MessageBoxChildWindowKeyUp;

            CloseCommand = new RelayCommand<bool>(CloseWindow);

            InitLabel();
        }

        #endregion

        /// <summary>
        ///   Handles the KeyUp event of the MessageBoxChildWindow control.
        /// </summary>
        /// <param name = "sender">The source of the event.</param>
        /// <param name = "e">The <see cref = "System.Windows.Input.KeyEventArgs" /> instance containing the event data.</param>
        private void MessageBoxChildWindowKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key
                == Key.Escape)
            {
                CloseWindow(true);
            }
        }

        /// <summary>
        ///   Translation
        /// </summary>
        public void InitLabel()
        {
            ButtonOK.Content = Resx.GetLabel(ResxCommon.OK);
            ButtonCancel.Content = Resx.GetLabel(ResxCommon.CANCEL);
        }

        private void CloseWindow(bool isCancelled)
        {
            DialogResult = !isCancelled;
            Close();
        }

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}